package com.jiaai.web.xiaoke.version;

import com.alibaba.dubbo.config.annotation.Reference;
import com.jiaai.exception.ServerException;
import com.jiaai.util.RestResultGenerator;
import com.jiaai.version.api.TCodeNumApi;
import com.jiaai.version.model.TCodeNumVO;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 佳爱网络科技
 * @since 2018-03-07
 */
@RestController
@RequestMapping("/api/v1/admin/code")
public class CodeNumController {
    @Reference
    TCodeNumApi tCodeNumApi;
    /**
     * 后台查询所有的消息记录
     * @param
     * @return
     * @throws Exception
     */
    @GetMapping("/findByAll")
    public Object findByAll(@RequestParam(defaultValue = "0", required = false)Integer curr, TCodeNumVO tCodeNumVO) throws ServerException {
        try {
            return RestResultGenerator.genSuccessResult(tCodeNumApi.findByAll(curr,tCodeNumVO));
        } catch (Exception e) {
            throw new ServerException("查询失败");
        }
    }

    @PostMapping("/add")
    public Object add(@RequestBody TCodeNumVO tCodeNumVO) throws ServerException {
        try {
            tCodeNumApi.addCodeNum(tCodeNumVO);
            return RestResultGenerator.genSuccessResult("添加成功");
        } catch (Exception e) {
            throw new ServerException("添加失败");
        }
    }


}
